package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_DOU_LUO_DA_LU_ZHUI_BU_SEARCH,desc = "玩家查询")
public class DouLuoDaLuUserSearchCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        if ((ret = DouLuoDaLuMgr.canEntryActivity(player)) != 0) return;

        DouLuoDaLuProto.DouLuoDaLuUserSearchReqMsg reqMsg = DouLuoDaLuProto.DouLuoDaLuUserSearchReqMsg.parseFrom(packet.getBytes());

        if(reqMsg.getUserAliasId() == player.getUserInfo().getUserAliasId() && reqMsg.getServerId() == GameServer.getInstance().getServerId()){
            ret = GameErrorCode.E_DOU_LUO_DA_LU_NOT_MATCH_SELF;
            return;
        }

        DouLuoDaLuProto.DouLuoDaLuUserSearchCrossReqMsg.Builder crossReq = DouLuoDaLuProto.DouLuoDaLuUserSearchCrossReqMsg.newBuilder();
        crossReq.setActivityId(DouLuoDaLuMgr.getActivityInfo().getActivityId());
        crossReq.setServerId(reqMsg.getServerId());
        crossReq.setUserAliasId(reqMsg.getUserAliasId());
        player.sendUnionActivityGroupPacket(Protocol.C_DOU_LUO_DA_LU_ZHUI_BU_SEARCH, crossReq, crossReq.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_DOU_LUO_DA_LU_ZHUI_BU_SEARCH, DouLuoDaLuProto.DouLuoDaLuUserSearchRespMsg.newBuilder().setRet(ret));
        }
    }
}
